const {
	Controller
} = require('dx-router-admin')
module.exports = class User extends Controller {

	constructor(ctx) {
		super(ctx)

	}
	//获取用户信息
	async getUserInfo() {
		let {
			$dx
		} = this;
		if (!$dx.auth) {
			this.error('请先登录');
		}
		const res = await $dx.uniID.getUserInfo({
			uid: $dx.auth.uid,
			// field: ['username,nickname,avatar,mobile']
		})
		if (!res.code) {
			delete res.userInfo.password;
		}
		this.echoJson(res);
	}
	//我的相册
	async myphoto() {
		let lastId = this.$dx.request.param('lastId');
		let res = await this.$dx.service.userphoto.where(this.$dx.request.param('where'))
			.where('user_id', this.$dx.auth.uid)
			.field('title,path,images')
			.paginate(lastId, 10, 0);

		this.echoJson('获取成功', res);
	}
	//我的图片
	async myimage() {

	}
	//删除我的相册
	async delphoto() {
		const {
			$dx
		} = this;
		const id = $dx.request.post('id');
		if (!id) {
			this.error('参数错误');
		}
		//符合条件的
		let row = await $dx.service.userphoto.where('_id', id).find();
		console.log(row.user_id,$dx.auth.uid)
		if (row.user_id != $dx.auth.uid) {
			this.error('不能越权操作');
		}
		//删除
		await row.delete();
		this.echoJson('删除成功');
	}

}
